<template>
    <a-spin :spinning="confirmLoading">
        <j-form-container :disabled="formDisabled">
            <!-- 主表单区域 -->
            <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
                <a-row>
                    <a-col :xs="24" :sm="8">
                        <a-form-model-item label="服务名" :labelCol="labelCol" :wrapperCol="wrapperCol"
                                           prop="serverCode">
                            <a-input v-model="model.serverCode" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :xs="24" :sm="8">
                        <a-form-model-item label="任务名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskCode">
                            <a-input v-model="model.taskCode"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :xs="24" :sm="8">
                        <a-form-model-item label="任务描述" :labelCol="labelCol" :wrapperCol="wrapperCol"
                                           prop="taskDesc">
                            <a-input v-model="model.taskDesc"></a-input>
                        </a-form-model-item>
                    </a-col>

                </a-row>
                <a-row>
                    <a-col :xs="24" :sm="22">
                        <a-form-model-item label="参数类" :labelCol="labelCol1" :wrapperCol="wrapperCol1"
                                           prop="paramClass">
                            <a-input v-model="model.paramClass"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :xs="24" :sm="22">
                        <a-form-model-item label="测试数据" :labelCol="labelCol1" :wrapperCol="wrapperCol1"
                                           prop="testData">
                            <a-textarea v-model="model.testData" rows="12" placeholder="请输入测试数据"/>
                        </a-form-model-item>
                    </a-col>

                </a-row>
            </a-form-model>
        </j-form-container>
    </a-spin>
</template>

<script>

    import { httpAction } from '@/api/manage'
    import ExoServerListPop from '../plugins/MsiExoServerListPop'

    export default {
        name: 'MsiServerTaskForm',
        mixins: [],
        components: {
            ExoServerListPop
        },
        data() {
            return {
                labelCol: {
                    xs: { span: 24 },
                    sm: { span: 5 },
                },
                wrapperCol: {
                    xs: { span: 24 },
                    sm: { span: 16 },
                },
                labelCol1: {
                    xs: { span: 24 },
                    sm: { span: 2 },
                },
                wrapperCol1: {
                    xs: { span: 24 },
                    sm: { span: 22 },
                },
                msiServer: {},
                model: {},
                confirmLoading: false,
                validatorRules: {
                    taskCode: [
                        { required: true, message: '请输入任务名!' },
                    ],
                    taskDesc: [
                        { required: true, message: '请输入任务描述!' },
                    ],
                    paramClass: [
                        { required: true, message: '请输入参数类!' },
                    ],
                },
                url: {
                    add: '/msibase/msiWsServerTask/add',
                    edit: '/msibase/msiExoSystem/edit',
                }
            }
        },
        props: {
            //表单禁用
            disabled: {
                type: Boolean,
                default: false,
                required: false
            }
        },
        computed: {
            formDisabled() {
                return this.disabled
            },
        },
        created() {
        },
        methods: {
            add(msiServer) {
                this.msiServer = msiServer
                this.edit()
            },
            edit(record) {
                this.model = Object.assign({}, {
                    serverId: this.msiServer.id,
                    serverCode: this.msiServer.serverCode
                }, record)
                this.visible = true
            },
            submitForm() {
                const that = this
                // 触发表单验证
                this.$refs.form.validate(valid => {
                    if (valid) {
                        that.confirmLoading = true
                        let httpurl = ''
                        let method = ''
                        if (!this.model.id) {
                            httpurl += this.url.add
                            method = 'post'
                        } else {
                            httpurl += this.url.edit
                            method = 'put'
                        }
                        httpAction(httpurl, this.model, method).then((res) => {
                            if (res.success) {
                                that.$message.success(res.message)
                                that.$emit('ok')
                            } else {
                                that.$message.warning(res.message)
                            }
                        }).finally(() => {
                            that.confirmLoading = false
                        })
                    }

                })
            },

        }
    }
</script>

<style scoped>
</style>
